<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>事件处理</title>
</head>

<body>
    <div id="example-1">
        <button v-on:click="counter += 1">Add 1</button>
        <p>The button above has been clicked {{counter}} times.</p>
    </div>
    <div id="example-2">
        <button v-on:click="greet">Greet</button>
    </div>
    <div id="example-3">
        <button v-on:click="say('hi')">Say hi</button>
        <button v-on:click="say('what')">Say what</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var example1 = new Vue({
            el: '#example-1',
            data: {
                counter: 0
            }
        })
        var example2 = new Vue({
            el: '#example-2',
            data: {
                name: 'Vue.js'
            },
            methods: {
                greet: function (event) {
                    //this在方法里指向当前Vue实例
                    alert('Hello' + this.name + '!')
                    if (event) {
                        alert(event.target.tagName)
                    }
                }
            }
        })
        var example3 = new Vue({
            el: '#example-3',
            methods: {
                say: function (message) {
                    alert(message)
                }
            }
        })
    </script>
</body>

</html>